package spec.caoyujuan.unit2_3;

import java.util.Scanner;

public class RentCalculation {
    public double calculateTotalRent() {
        double totalRent = 0;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入租金");
        double monthRent = sc.nextDouble();
        System.out.println("请输入租金时间（以月为单位）:");
        int month = sc.nextInt();
        System.out.println("请输入物业费用 ");
        double propertyCost = sc.nextDouble();
        System.out.println("请输入其他费用: ");
        double otherCost = sc.nextDouble();
        totalRent += monthRent * month;
        totalRent += propertyCost * month;
        totalRent += otherCost;
        return totalRent;
    }

    public double averageRent(double totalRent) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入合租人数: ");
        int numbers = sc.nextInt();
        return totalRent / numbers;
    }

    public static void main(String[] args) {
        RentCalculation rentCal = new RentCalculation();
        Scanner sc = new Scanner(System.in);
        System.out.println("欢迎你使用房屋租赁管理系统租金计算工具！");
        s1:
        while (true) {
            System.out.println("1:计算总的租金");
            double totalRent = rentCal.calculateTotalRent();
            System.out.println("总的租金是:" + totalRent);
            System.out.println("2:计算个人租金");
            double averRent = rentCal.averageRent(totalRent);
            averRent = Math.round(averRent);
            System.out.println("个人的租金是:" + averRent);
            System.out.println("是否继续: 1:继续  2:退出");
            for (; ; ) {
                int nextAction = sc.nextInt();
                if (nextAction == 1) {
                    continue s1;
                } else if (nextAction == 2) {
                    break s1;
                } else {
                    System.out.println("你的输入有错，请重新输入！");
                    continue;
                }
            }
        }
        System.out.println("恭喜你，你已经成功退出啦！");
    }
}